import {
  getCompanyID,
  getLevelFirst,
  getLevelZero,
  getUserDepID,
  getUserID,
} from '@/utils';

/**
 * 定义公告管理头部切换
 * @param permissions
 * @returns
 */
const getAnnounceManageTabSwitch = (permissions: Record<string, any>) => {
  /** 公告管理 */
  const MyAnnouceManageTab = () => {
    if (permissions?.['/announceController/ownCompanyID']) {
      return {
        ownCompanyID: getLevelZero(),
        params: 'ownCompanyID',
        ownType: null,
        queryType: 0,
      };
    } else if (permissions?.['/announceController/ownDepartmentID']) {
      return {
        ownDepartmentID: getLevelFirst(),
        params: 'ownDepartmentID',
        ownType: null,
        queryType: 1,
      };
    } else if (permissions?.['/announceController/ownerID']) {
      return {
        ownerID: getUserID(),
        params: 'ownerID',
        ownType: null,
        queryType: 2,
      };
    }
  };

  /** 公告签发 */
  const MyAnnouceSignTab = () => {
    if (permissions?.['/announceController/signCompanyID']) {
      return {
        signCompanyID: getLevelZero(),
        params: 'signCompanyID',
        ownType: null,
        queryType: 0,
      };
    } else if (permissions?.['/announceController/signDepartmentID']) {
      return {
        signDepartmentID: getLevelFirst(),
        params: 'signDepartmentID',
        ownType: null,
        queryType: 1,
      };
    } else if (permissions?.['/announceController/signerID']) {
      return {
        signerID: getUserID(),
        params: 'signerID',
        ownType: null,
        queryType: 2,
      };
    }
  };

  /** 公告审核 */
  const MyAnnouceCheckTab = () => {
    if (permissions?.['/announceController/checkCompanyID']) {
      return {
        checkCompanyID: getLevelZero(),
        params: 'checkCompanyID',
        checkState: '0',
        ownType: null,
        queryType: 0,
      };
    } else if (permissions?.['/announceController/checkDepartmentID']) {
      return {
        checkDepartmentID: getLevelFirst(),
        params: 'checkDepartmentID',
        checkState: '0',
        ownType: null,
        queryType: 1,
      };
    } else if (permissions?.['/announceController/checkerID']) {
      return {
        checkerID: getUserID(),
        params: 'checkerID',
        checkState: '0',
        ownType: null,
        queryType: 2,
      };
    }
  };

  return [
    {
      title: '公告管理',
      key: 'MyAnnouceManageTab',
      visible:
        (permissions?.['/announceController/ownCompanyID'] ||
          permissions?.['/announceController/ownDepartmentID'] ||
          permissions?.['/announceController/ownerID']) ??
        false,
      md: 2,
      sm: 24,
      params: MyAnnouceManageTab(),
    },
    {
      title: '公告签发',
      key: 'MyAnnouceSignTab',
      visible:
        (permissions?.['/announceController/signCompanyID'] ||
          permissions?.['/announceController/signDepartmentID'] ||
          permissions?.['/announceController/signerID']) ??
        false,
      md: 2,
      sm: 24,
      params: MyAnnouceSignTab(),
    },
    {
      title: '公告审核',
      key: 'MyAnnouceCheckTab',
      visible:
        (permissions?.['/announceController/checkCompanyID'] ||
          permissions?.['/announceController/checkDepartmentID'] ||
          permissions?.['/announceController/checkerID']) ??
        false,
      md: 2,
      sm: 24,
      params: MyAnnouceCheckTab(),
    },
  ];
};

export { getAnnounceManageTabSwitch };
